package com.king.modules.system.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson2.JSONObject;
import com.king.common.constant.Constants;
import com.king.common.constant.UserConstants;
import com.king.common.exception.AssertHelper;
import com.king.common.utils.SecurityUtils;
import com.king.common.utils.TreeUtils;
import com.king.common.utils.bean.BeanUtils;
import com.king.common.utils.text.StringUtils;
import com.king.framework.base.domain.vo.AjaxResult;
import com.king.framework.base.domain.vo.LoginUser;
import com.king.framework.base.domain.vo.PageResult;
import com.king.framework.base.service.TreeInterface;
import com.king.framework.base.service.impl.YyTreeServiceImpl;
import com.king.modules.system.domain.SysGroupMenuEntity;
import com.king.modules.system.domain.SysMenuEntity;
import com.king.modules.system.domain.SysUserEntity;
import com.king.modules.system.domain.vo.RouterVo;
import com.king.modules.system.mapper.SysMenuMapper;
import com.king.modules.system.service.SysGroupMenuService;
import com.king.modules.system.service.SysMenuService;
import com.king.modules.system.service.SysRoleMenuService;

/**
 * 菜单 业务层处理
 * 
 * @author king
 */
@Service
public class SysMenuServiceImpl extends YyTreeServiceImpl<SysMenuMapper, SysMenuEntity, Long> implements SysMenuService {
	
	@Autowired
	private SysMenuMapper menuMapper;
	@Autowired
	private SysRoleMenuService sysRoleMenuService;
	@Autowired
	private SysGroupMenuService groupMenuService;

	@Override
	public void setBtnInfoByParent(SysMenuEntity menu,SysMenuEntity parent){
		menu.setName(parent.getName());
	}
	
	@Override
	public void afterUpdate(SysMenuEntity oldEntity, SysMenuEntity entity) throws Exception {
		if(!entity.getMenutype().equals(UserConstants.TYPE_BUTTON)){
			List<SysMenuEntity> childList = findByParentid(entity.getId());
			for(SysMenuEntity menu : childList){
				if(menu.getMenutype().equals(UserConstants.TYPE_BUTTON)){
					setBtnInfoByParent(menu, entity);
					doUpdate(menu);
				}
			}
		}
		super.afterUpdate(oldEntity, entity);
	}


	@Override
	public void beforeDelete(SysMenuEntity entity) throws Exception {
		AssertHelper.getInstance().checkException(checkMenuExistRole(entity.getId()), "已关联角色不能删除");
		super.beforeDelete(entity);
	}
	
	
	@Transactional
	@Override
	public AjaxResult copy(Long id) throws Exception {
		SysMenuEntity menu = findByPK(id);
		AssertHelper.getInstance().checkNullException(menu, "不存在菜单:"+id);
		
		SysMenuEntity entity = new SysMenuEntity();
		BeanUtils.copyBeanProp(entity, menu);
		entity.setId(null);
		entity.setNodename(menu.getNodename()+System.currentTimeMillis());
		entity.setShoworder(menu.getShoworder()+1);
		entity = doAdd(entity);
		
		return AjaxResult.success(entity);
	}
	/**
	 * 根据用户查询系统菜单列表
	 * 
	 * @param userId
	 *            用户ID
	 * @return 菜单列表
	 */
	@Override
	public List<SysMenuEntity> selectGroupMenuList(LoginUser user) {
		if(SecurityUtils.isAdmin(user.getUserId())){
			return  menuMapper.selectMenuListAll(new SysMenuEntity());
		}
		return menuMapper.selectMenuListByGroupid(user.getGroupid());
	}

	/**
	 * 查询系统菜单列表
	 * 
	 * @param menu
	 *            菜单信息
	 * @return 菜单列表
	 */
	@Override
	public List<SysMenuEntity> selectMenuList(SysMenuEntity menu, Long userId) {
		List<SysMenuEntity> menuList = null;
		// 管理员显示所有菜单信息
		if (SysUserEntity.isAdmin(userId)) {
			menuList = menuMapper.selectMenuListAll(menu);
		} else {
			Map<String, Object> params = menu.getParams();
			if(params == null){
				params = new HashMap<String, Object>();
			}
			params.put("userId", userId);
			menu.setParams(params);
			menuList = menuMapper.selectMenuListByUserId(menu);
			
			List<SysGroupMenuEntity> groupMenuList = groupMenuService.findByGroupid(SecurityUtils.getGroupid());
			Map<Long, SysGroupMenuEntity> groupMenuMap = groupMenuList.stream()
		            .collect(Collectors.toMap(SysGroupMenuEntity::getMenuid, Function.identity(), (v1, v2) -> v2));
			
			for (SysMenuEntity m : menuList) {
				SysGroupMenuEntity groupMenu = null;
				groupMenu = groupMenuMap.get(m.getId());
				if(groupMenu == null){
					continue;
				}
				m.setNodename(groupMenu.getMenualias());
				m.setShoworder(groupMenu.getShoworder());
			}	
			
			//重新排序
			Collections.sort(menuList, new Comparator<SysMenuEntity>() {
				@Override
				public int compare(SysMenuEntity arg0, SysMenuEntity arg1) {
					return arg0.getShoworder().compareTo(arg1.getShoworder());
				}
			});
			
		}
		return menuList;
	}

	/**
	 * 根据用户ID查询权限
	 * 
	 * @param userId
	 *            用户ID
	 * @return 权限列表
	 */
	@Override
	public Set<String> selectMenuPermsByUserId(Long userId) {
		List<String> perms = menuMapper.selectMenuPermsByUserId(userId);
		Set<String> permsSet = new HashSet<>();
		for (String perm : perms) {
			if (StringUtils.isNotEmpty(perm)) {
				permsSet.addAll(Arrays.asList(perm.trim().split(",")));
			}
		}
		return permsSet;
	}


	/**
	 * 根据角色ID查询菜单树信息
	 * 
	 * @param roleId
	 *            角色ID
	 * @return 选中菜单列表
	 */
	@Override
	public List<Long> selectMenuIdsByRoleId(Long roleId) {
		return menuMapper.selectMenuIdsByRoleId(roleId);
	}


	/**
	 * 查询菜单使用数量
	 * 
	 * @param menuId
	 *            菜单ID
	 * @return 结果
	 */
	@Override
	public boolean checkMenuExistRole(Long menuId) {
		int result = sysRoleMenuService.checkMenuExistRole(menuId);
		return result > 0;
	}



	@Override
	public List<SysGroupMenuEntity> queryOwnMenuRes(SysMenuEntity form) {
		return menuMapper.queryOwnMenuRes(form);
	}

	

	/**
	 * 根据用户ID查询菜单
	 * 
	 * @param userId
	 *            用户名称
	 * @return 菜单列表
	 */
	@Override
	public AjaxResult selectRouteResByUserId(Long userId) {
		List<SysMenuEntity> menuResList = selectMenuList(new SysMenuEntity(), userId);
		Map<Long, SysMenuEntity> menuMap = menuResList.stream().collect(Collectors.toMap(obj -> obj.getId(), Function.identity()));
		
		List<TreeInterface> menuList = new ArrayList<>();
		Map<String,List<String>> buttonMap = new HashMap<>();
		String routeName = "";
		List<String> routeBtnList = null;
		
		for (SysMenuEntity menu : menuResList) {
			if (menu.getMenutype().equals(UserConstants.TYPE_BUTTON)) {
				routeName = menuMap.get(menu.getParentid()).getName();
				routeBtnList = buttonMap.get(routeName);
				if(routeBtnList == null){
					routeBtnList = new ArrayList<>();
				}
				routeBtnList.add(menu.getPath());
				buttonMap.put(routeName, routeBtnList);
				
				continue;//按钮不返回
			}
			if(menu.getId().longValue() == Constants.TREE_MENU_ROOTID){
				continue;//根节点不返回
			}
			menuList.add(new RouterVo(menu));
		}
		
		//构建树
		List<TreeInterface> routerList = TreeUtils.buildTree(menuList);
		
//		List<RouterVo> defaultList = JSON.parseArray("[{\"path\":\"/home/index\",\"name\":\"home\",\"component\":\"/home/index\",\"meta\":{\"icon\":\"HomeFilled\",\"title\":\"首页\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":true,\"isKeepAlive\":true}},{\"path\":\"/dataScreen\",\"name\":\"dataScreen\",\"component\":\"/dataScreen/index\",\"meta\":{\"icon\":\"Histogram\",\"title\":\"数据大屏\",\"isLink\":\"\",\"isHide\":false,\"isFull\":true,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/proTable\",\"name\":\"proTable\",\"redirect\":\"/proTable/useProTable\",\"meta\":{\"icon\":\"MessageBox\",\"title\":\"超级表格\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/proTable/useProTable\",\"name\":\"useProTable\",\"component\":\"/proTable/useProTable/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"使用 ProTable\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/proTable/useProTable/detail/:id\",\"name\":\"useProTableDetail\",\"component\":\"/proTable/useProTable/detail\",\"meta\":{\"icon\":\"Menu\",\"title\":\"ProTable 详情\",\"activeMenu\":\"/proTable/useProTable\",\"isLink\":\"\",\"isHide\":true,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/proTable/useTreeFilter\",\"name\":\"useTreeFilter\",\"component\":\"/proTable/useTreeFilter/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"使用 TreeFilter\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/proTable/useTreeFilter/detail/:id\",\"name\":\"useTreeFilterDetail\",\"component\":\"/proTable/useTreeFilter/detail\",\"meta\":{\"icon\":\"Menu\",\"title\":\"TreeFilter 详情\",\"activeMenu\":\"/proTable/useTreeFilter\",\"isLink\":\"\",\"isHide\":true,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/proTable/useSelectFilter\",\"name\":\"useSelectFilter\",\"component\":\"/proTable/useSelectFilter/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"使用 SelectFilter\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/proTable/treeProTable\",\"name\":\"treeProTable\",\"component\":\"/proTable/treeProTable/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"树形 ProTable\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/proTable/complexProTable\",\"name\":\"complexProTable\",\"component\":\"/proTable/complexProTable/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"复杂 ProTable\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/proTable/document\",\"name\":\"proTableDocument\",\"component\":\"/proTable/document/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"ProTable 文档\",\"isLink\":\"https://juejin.cn/post/7166068828202336263/#heading-14\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/auth\",\"name\":\"auth\",\"redirect\":\"/auth/menu\",\"meta\":{\"icon\":\"Lock\",\"title\":\"权限管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/auth/menu\",\"name\":\"authMenu\",\"component\":\"/auth/menu/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单权限\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/auth/button\",\"name\":\"authButton\",\"component\":\"/auth/button/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"按钮权限\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/assembly\",\"name\":\"assembly\",\"redirect\":\"/assembly/guide\",\"meta\":{\"icon\":\"Briefcase\",\"title\":\"常用组件\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/assembly/guide\",\"name\":\"guide\",\"component\":\"/assembly/guide/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"引导页\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/tabs\",\"name\":\"tabs\",\"component\":\"/assembly/tabs/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"标签页操作\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/assembly/tabs/detail/:id\",\"name\":\"tabsDetail\",\"component\":\"/assembly/tabs/detail\",\"meta\":{\"icon\":\"Menu\",\"title\":\"Tab 详情\",\"activeMenu\":\"/assembly/tabs\",\"isLink\":\"\",\"isHide\":true,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/assembly/selectIcon\",\"name\":\"selectIcon\",\"component\":\"/assembly/selectIcon/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"图标选择器\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/selectFilter\",\"name\":\"selectFilter\",\"component\":\"/assembly/selectFilter/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"分类筛选器\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/treeFilter\",\"name\":\"treeFilter\",\"component\":\"/assembly/treeFilter/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"树形筛选器\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/svgIcon\",\"name\":\"svgIcon\",\"component\":\"/assembly/svgIcon/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"SVG 图标\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/uploadFile\",\"name\":\"uploadFile\",\"component\":\"/assembly/uploadFile/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"文件上传\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/batchImport\",\"name\":\"batchImport\",\"component\":\"/assembly/batchImport/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"批量添加数据\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/wangEditor\",\"name\":\"wangEditor\",\"component\":\"/assembly/wangEditor/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"富文本编辑器\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/assembly/draggable\",\"name\":\"draggable\",\"component\":\"/assembly/draggable/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"拖拽组件\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/dashboard\",\"name\":\"dashboard\",\"redirect\":\"/dashboard/dataVisualize\",\"meta\":{\"icon\":\"Odometer\",\"title\":\"Dashboard\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/dashboard/dataVisualize\",\"name\":\"dataVisualize\",\"component\":\"/dashboard/dataVisualize/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"数据可视化\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/dashboard/embedded\",\"name\":\"embedded\",\"component\":\"/dashboard/embedded/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"内嵌页面\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/form\",\"name\":\"form\",\"redirect\":\"/form/proForm\",\"meta\":{\"icon\":\"Tickets\",\"title\":\"表单 Form\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/form/proForm\",\"name\":\"proForm\",\"component\":\"/form/proForm/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"超级 Form\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/form/basicForm\",\"name\":\"basicForm\",\"component\":\"/form/basicForm/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"基础 Form\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/form/validateForm\",\"name\":\"validateForm\",\"component\":\"/form/validateForm/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"校验 Form\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/form/dynamicForm\",\"name\":\"dynamicForm\",\"component\":\"/form/dynamicForm/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"动态 Form\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/echarts\",\"name\":\"echarts\",\"redirect\":\"/echarts/waterChart\",\"meta\":{\"icon\":\"TrendCharts\",\"title\":\"Echarts\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/echarts/waterChart\",\"name\":\"waterChart\",\"component\":\"/echarts/waterChart/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"水型图\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/echarts/columnChart\",\"name\":\"columnChart\",\"component\":\"/echarts/columnChart/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"柱状图\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/echarts/lineChart\",\"name\":\"lineChart\",\"component\":\"/echarts/lineChart/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"折线图\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/echarts/pieChart\",\"name\":\"pieChart\",\"component\":\"/echarts/pieChart/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"饼图\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/echarts/radarChart\",\"name\":\"radarChart\",\"component\":\"/echarts/radarChart/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"雷达图\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/echarts/nestedChart\",\"name\":\"nestedChart\",\"component\":\"/echarts/nestedChart/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"嵌套环形图\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/directives\",\"name\":\"directives\",\"redirect\":\"/directives/copyDirect\",\"meta\":{\"icon\":\"Stamp\",\"title\":\"自定义指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/directives/copyDirect\",\"name\":\"copyDirect\",\"component\":\"/directives/copyDirect/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"复制指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/directives/watermarkDirect\",\"name\":\"watermarkDirect\",\"component\":\"/directives/watermarkDirect/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"水印指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/directives/dragDirect\",\"name\":\"dragDirect\",\"component\":\"/directives/dragDirect/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"拖拽指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/directives/debounceDirect\",\"name\":\"debounceDirect\",\"component\":\"/directives/debounceDirect/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"防抖指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/directives/throttleDirect\",\"name\":\"throttleDirect\",\"component\":\"/directives/throttleDirect/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"节流指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/directives/longpressDirect\",\"name\":\"longpressDirect\",\"component\":\"/directives/longpressDirect/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"长按指令\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/menu\",\"name\":\"menu\",\"redirect\":\"/menu/menu1\",\"meta\":{\"icon\":\"List\",\"title\":\"菜单嵌套\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/menu/menu1\",\"name\":\"menu1\",\"component\":\"/menu/menu1/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单1\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/menu/menu2\",\"name\":\"menu2\",\"redirect\":\"/menu/menu2/menu21\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单2\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/menu/menu2/menu21\",\"name\":\"menu21\",\"component\":\"/menu/menu2/menu21/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单2-1\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/menu/menu2/menu22\",\"name\":\"menu22\",\"redirect\":\"/menu/menu2/menu22/menu221\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单2-2\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/menu/menu2/menu22/menu221\",\"name\":\"menu221\",\"component\":\"/menu/menu2/menu22/menu221/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单2-2-1\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/menu/menu2/menu22/menu222\",\"name\":\"menu222\",\"component\":\"/menu/menu2/menu22/menu222/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单2-2-2\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/menu/menu2/menu23\",\"name\":\"menu23\",\"component\":\"/menu/menu2/menu23/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单2-3\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/menu/menu3\",\"name\":\"menu3\",\"component\":\"/menu/menu3/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单3\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/system\",\"name\":\"system\",\"redirect\":\"/system/accountManage\",\"meta\":{\"icon\":\"Tools\",\"title\":\"系统管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/system/accountManage\",\"name\":\"accountManage\",\"component\":\"/system/accountManage/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"账号管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/system/roleManage\",\"name\":\"roleManage\",\"component\":\"/system/roleManage/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"角色管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/system/menuMange\",\"name\":\"menuMange\",\"component\":\"/system/menuMange/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"菜单管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/system/departmentManage\",\"name\":\"departmentManage\",\"component\":\"/system/departmentManage/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"部门管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/system/dictManage\",\"name\":\"dictManage\",\"component\":\"/system/dictManage/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"字典管理\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/system/timingTask\",\"name\":\"timingTask\",\"component\":\"/system/timingTask/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"定时任务\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/system/systemLog\",\"name\":\"systemLog\",\"component\":\"/system/systemLog/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"系统日志\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/link\",\"name\":\"link\",\"redirect\":\"/link/gitee\",\"meta\":{\"icon\":\"Paperclip\",\"title\":\"外部链接\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true},\"children\":[{\"path\":\"/link/gitee\",\"name\":\"gitee\",\"component\":\"/link/gitee/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"Gitee 仓库\",\"isLink\":\"https://gitee.com/HalseySpicy/king-Admin\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/link/github\",\"name\":\"github\",\"component\":\"/link/github/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"GitHub 仓库\",\"isLink\":\"https://github.com/HalseySpicy/king-Admin\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/link/kingDocs\",\"name\":\"kingDocs\",\"component\":\"/link/kingDocs/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"项目文档\",\"isLink\":\"https://docs.spicyboy.cn\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}},{\"path\":\"/link/juejin\",\"name\":\"juejin\",\"component\":\"/link/juejin/index\",\"meta\":{\"icon\":\"Menu\",\"title\":\"掘金主页\",\"isLink\":\"https://juejin.cn/user/3263814531551816/posts\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]},{\"path\":\"/about/index\",\"name\":\"about\",\"component\":\"/about/index\",\"meta\":{\"icon\":\"InfoFilled\",\"title\":\"关于项目\",\"isLink\":\"\",\"isHide\":false,\"isFull\":false,\"isAffix\":false,\"isKeepAlive\":true}}]", RouterVo.class);
//		routerList.addAll(defaultList);
		
		
		AjaxResult result = AjaxResult.success();
		JSONObject datas = new JSONObject();
		datas.put("routeList", routerList);
		datas.put("buttonList", buttonMap);
		result.put("data", datas);
		return result;
	}


	@Override
	public AjaxResult queryMenuRes(Map<String, Object> searchMap) throws Exception {
		Map<String, Object> params = new HashMap<>();
		params.put("EQ_parentid", searchMap.get("menuid"));
		params.put("EQ_menutype", UserConstants.TYPE_BUTTON);
		PageResult<SysMenuEntity> datas = doQuery(params);
        return AjaxResult.success(datas);
	}
	


}
